package sxe.core.math;

import snobject.snDouble;
import snobject.snObject;
import snobject.snObjectArgList;
import step.FunctionWrapper;
import step.EvaluationFailure;
import sxe.core.EvaluationFailureReasons;

/**
 * Returns the natural logarithm (base e) of a double value.
 * @param argv must contain an snDouble object at top of the stack
 * @return returns the snDouble value of the value ln a, the natural logarithm of a
 */

public class log extends FunctionWrapper{
	
	public snObject Call(snObjectArgList argv) throws EvaluationFailure{
		// REQUIRES: argv must contain an snDouble object at top of the stack
		// EFFECTS: if argv contains a value <= 0, throw EvaluationFailure exception
		//			returns the snDouble value of the value ln a, the natural logarithm of a
		double ret = argv.popDouble().getDbl();
		
		if(ret<=0)
			throw new EvaluationFailure(super.expnode,
					EvaluationFailureReasons.NEGATIVE_LOG);
		
		return new snDouble(Math.log(ret));
	}
}